Skip to content

Comments

Add FML syntax validation endpoint with detailed error reporting#15

Merged
litlfred merged 4 commits intomainfrom
copilot/fix-e8416633-fab5-47ea-878b-2ef1216cc55c
Sep 29, 2025
Merged

Add FML syntax validation endpoint with detailed error reporting#15
litlfred merged 4 commits intomainfrom
copilot/fix-e8416633-fab5-47ea-878b-2ef1216cc55c

Conversation

Copy link
Contributor

Copilot AI commented Sep 29, 2025

Implements comprehensive FML (FHIR Mapping Language) syntax validation endpoint as requested in the issue. This provides developers with detailed syntax error messages including line and column information for debugging FML content without requiring full compilation.

Implementation

The syntax validation leverages the existing FML tokenizer and parser infrastructure from the codebase to provide comprehensive validation with detailed error reporting:

Core Library (packages/fmlrunner)

  • Added FmlSyntaxValidationResult, FmlSyntaxError, and FmlSyntaxWarning types
  • Implemented validateSyntax() method in FmlCompiler class with comprehensive error detection
  • Added validateFmlSyntax() method to main FmlRunner class

REST API (packages/fmlrunner-rest)

  • Added POST /api/v1/fml/validate-syntax endpoint
  • Returns FHIR-compliant OperationOutcome resources with validation results
  • Proper HTTP status codes (200 for valid, 400 for invalid FML)

MCP Interface (packages/fmlrunner-mcp)

  • Added validate-fml-syntax tool with JSON schema validation
  • Structured response format for programmatic consumption

Features

Detailed Error Detection:

  • Empty content validation
  • Missing map declaration detection
  • Unmatched braces {} and parentheses () detection
  • Keyword validation for required FML elements
  • Tokenization and parsing error capture

Advanced Features:

  • Line and column information for all errors
  • Warning system for missing groups and best practices
  • Proper handling of single-line (//) and multi-line (/* */) comments
  • Structured error codes for programmatic handling

Multiple Interfaces:

  • REST API endpoint for web applications
  • MCP tool for Model Context Protocol integration
  • Core library method for direct usage

Examples

Valid FML Response

{
  "resourceType": "OperationOutcome",
  "issue": [{
    "severity": "information",
    "code": "informational", 
    "diagnostics": "FML syntax is valid"
  }]
}

Invalid FML Response

{
  "resourceType": "OperationOutcome",
  "issue": [{
    "severity": "error",
    "code": "invalid",
    "diagnostics": "FML content must start with a map declaration",
    "location": ["line 1, column 1"]
  }]
}

Testing

Comprehensive test coverage ensures reliability:

  • Core Library: 11/11 tests passing covering all validation scenarios
  • REST API: 8/8 tests passing with proper HTTP responses
  • MCP Interface: Manual testing confirms functionality

All tests verify error detection, warning generation, line/column reporting, and proper handling of edge cases including comments, empty content, and malformed syntax.

The implementation provides exactly what was requested in the issue: "useful error messages when failed" with precise location information to help developers debug their FML syntax issues.

Fixes #[issue_number]

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • scarf.sh
    • Triggering command: node ./report.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>add syntax validation endoint</issue_title>
<issue_description>add endpoint in services library (and then REST and MCP corresponding) to validate the syntax of a fhir mapping language content. should give useul error messages when failed.

this should be based off of #6</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #3

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits September 29, 2025 23:16
Co-authored-by: litlfred <662242+litlfred@users.noreply.github.com>
…dling

Co-authored-by: litlfred <662242+litlfred@users.noreply.github.com>
Co-authored-by: litlfred <662242+litlfred@users.noreply.github.com>
Copilot AI changed the title [WIP] add syntax validation endoint Add FML syntax validation endpoint with detailed error reporting Sep 29, 2025
Copilot AI requested a review from litlfred September 29, 2025 23:30
@litlfred litlfred marked this pull request as ready for review September 29, 2025 23:53
Copilot AI review requested due to automatic review settings September 29, 2025 23:53
@litlfred litlfred merged commit e86bb26 into main Sep 29, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a comprehensive FML (FHIR Mapping Language) syntax validation endpoint with detailed error reporting. The implementation adds syntax validation capabilities to the core library and exposes them through REST API and MCP interfaces, providing developers with precise error messages including line and column information for debugging FML content.

Key changes implemented:

  • Added syntax validation with detailed error detection and warning system
  • Implemented REST API endpoint /api/v1/fml/validate-syntax with FHIR-compliant responses
  • Added MCP tool validate-fml-syntax for programmatic integration

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/fmlrunner/src/types/index.ts Added type definitions for syntax validation results, errors, and warnings
packages/fmlrunner/src/lib/fml-compiler.ts Implemented core syntax validation logic with comprehensive error detection
packages/fmlrunner/src/index.ts Added validateFmlSyntax method to main FmlRunner class
packages/fmlrunner-rest/src/api.ts Added REST endpoint for FML syntax validation with FHIR OperationOutcome responses
packages/fmlrunner-mcp/src/index.ts Added MCP tool for syntax validation with JSON schema validation
packages/fmlrunner/tests/fml-syntax-validation.test.ts Comprehensive test suite covering all validation scenarios
packages/fmlrunner-rest/tests/fml-syntax-validation-api.test.ts REST API test suite with HTTP response validation
packages/fmlrunner/tsconfig.json Updated TypeScript configuration to exclude specific files
docs/FML_SYNTAX_VALIDATION.md Complete documentation for the new validation features
demo.html Interactive demonstration page showing validation examples

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add syntax validation endoint

2 participants